package com.example.wisdomclassroomapi.domain.repository;

import com.example.wisdomclassroomapi.domain.entity.GradeUserBindEntity;
import com.example.wisdomclassroomapi.infrastructure.mapper.GradeUserBindMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
import java.util.List;
/**
 * @Package: com.example.wisdomclassroomapi.domain.repository
 * @Description: <>
 * @Author: scholes
 * @CreateDate: 2022-04-21
 * @UpdateUser: scholes
 * @UpdateDate: 2022-04-21
 * @UpdateRemark: <>
 * @Version: 1.0
 */
@Repository
public class GradeUserBindRepository {
    @Resource
    private GradeUserBindMapper gradeUserBindMapper;

    public void add(GradeUserBindEntity entity) {
       gradeUserBindMapper.insert(entity);
    }

    public GradeUserBindEntity findById(String id) {
        return gradeUserBindMapper.selectById(id);
    }

    public int updateById(GradeUserBindEntity entity) {
        return gradeUserBindMapper.updateById(entity);
    }

    public int deleteById(String id) {
        return gradeUserBindMapper.deleteById(id);
    }

    public IPage<GradeUserBindEntity> page(GradeUserBindEntity entity,IPage page) {
        QueryWrapper<GradeUserBindEntity> wrapper = new QueryWrapper<>();
            if (StringUtils.isNotBlank(entity.getUserId())){
            wrapper.eq("user_id",entity.getUserId());
            }
            if (StringUtils.isNotBlank(entity.getGradeId())){
            wrapper.eq("grade_id",entity.getGradeId());
            }
        return gradeUserBindMapper.selectPage(page, wrapper);
    }

    public List<GradeUserBindEntity> list(GradeUserBindEntity entity) {
        QueryWrapper<GradeUserBindEntity> wrapper = new QueryWrapper<>();
            if (StringUtils.isNotBlank(entity.getUserId())){
            wrapper.eq("user_id",entity.getUserId());
            }
            if (StringUtils.isNotBlank(entity.getGradeId())){
            wrapper.eq("grade_id",entity.getGradeId());
            }
        return gradeUserBindMapper.selectList(wrapper);
    }

}